package com.baibei.model;

import com.google.gson.annotations.SerializedName;

/**
 * 行情信息
 * Created by ChenRui on 2017/5/8 0008 16:40.
 */
public class QuotationInfo {

    @SerializedName("productId")
    private int productCode;

    private String productName;

    @SerializedName("lastPrice")
    private double marketPrice;

    @SerializedName("time")
    private String marketTime;

    private double open;

    @SerializedName("close")
    private double preClose;

    private double high;

    private double low;

    @SerializedName("amount")
    private double volume;

    @SerializedName("turnover")
    private double amount;

    private double last;

    public double getLast() {
        return last;
    }

    public void setLast(double last) {
        this.last = last;
    }

    public int getProductCode() {
        return productCode;
    }

    public void setProductCode(int productCode) {
        this.productCode = productCode;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public double getMarketPrice() {
        return marketPrice;
    }

    public void setMarketPrice(double marketPrice) {
        this.marketPrice = marketPrice;
    }

    public String getMarketTime() {
        return marketTime;
    }

    public void setMarketTime(String marketTime) {
        this.marketTime = marketTime;
    }

    public double getOpen() {
        return open;
    }

    public void setOpen(double open) {
        this.open = open;
    }

    public double getPreClose() {
        return preClose;
    }

    public void setPreClose(double preClose) {
        this.preClose = preClose;
    }

    public double getHigh() {
        return high;
    }

    public void setHigh(double high) {
        this.high = high;
    }

    public double getLow() {
        return low;
    }

    public void setLow(double low) {
        this.low = low;
    }

    public double getVolume() {
        return volume;
    }

    public void setVolume(double volume) {
        this.volume = volume;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }


    /**
     * 增长量
     */
    public double getScope() {
        return (marketPrice - preClose) / 100.00d;
    }

    /**
     * 增长率
     */
    public double getScopePercent() {
        if (preClose == 0) return 0; // 被除数不能为零
        return ((marketPrice * 1.0f - preClose * 1.0f) / preClose * 1.0f);
    }


    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.productName);
        sb.append(":");
        sb.append(this.marketPrice);
        sb.append("\n");

        sb.append("open = ");
        sb.append(this.open);
        sb.append("\n");

        sb.append("close = ");
        sb.append(this.preClose);
        sb.append("\n");

        sb.append("high = ");
        sb.append(this.high);
        sb.append("\n");

        sb.append("low = ");
        sb.append(this.low);
        sb.append("\n");

        sb.append("volume = ");
        sb.append(this.volume);
        sb.append("\n");

        sb.append("amount = ");
        sb.append(this.amount);
        sb.append("\n");

        sb.append("Scope = ");
        sb.append(getScope());
        sb.append("\n");

        sb.append("Percent = ");
        sb.append(getScopePercent());
        sb.append("\n");


        return sb.toString();
    }
}
